using System;

// 事件参数类
public class BigMoneyArgs : EventArgs
{
    public string AccountNumber { get; }
    public decimal Amount { get; }

    public BigMoneyArgs(string accountNumber, decimal amount)
    {
        AccountNumber = accountNumber;
        Amount = amount;
    }
}

// 账号基类
public class Account
{
    public string AccountNumber { get; set; }
    public decimal Balance { get; protected set; }

    public virtual void Deposit(decimal amount)
    {
        Balance += amount;
    }

    public virtual bool Withdraw(decimal amount)
    {
        if (amount > Balance) return false;
        Balance -= amount;
        return true;
    }
}

// 信用账号子类
public class CreditAccount : Account
{
    public decimal CreditLimit { get; set; }

    public override bool Withdraw(decimal amount)
    {
        if (amount > Balance + CreditLimit) return false;
        Balance -= amount;
        return true;
    }
}

// 自定义异常类
public class BadCashException : Exception
{
    public BadCashException(string message) : base(message) { }
}

// ATM 机类
public class ATM
{
    public event EventHandler<BigMoneyArgs> BigMoneyFetched;

    public void Withdraw(Account account, decimal amount)
    {
        if (new Random().Next(1, 10) <= 3)
        {
            throw new BadCashException("ATM 检测到坏钞票！");
        }

        if (account.Withdraw(amount))
        {
            Console.WriteLine($"取款成功，余额：{account.Balance}");
            if (amount > 10000)
            {
                BigMoneyFetched?.Invoke(this, new BigMoneyArgs(account.AccountNumber, amount));
            }
        }
        else
        {
            Console.WriteLine("余额不足，取款失败。");
        }
    }
}

// 测试程序
class Program
{
    static void Main()
    {
        ATM atm = new ATM();
        atm.BigMoneyFetched += (sender, e) =>
        {
            Console.WriteLine($"警告！账号 {e.AccountNumber} 取款 {e.Amount} 元。");
        };

        Account account = new CreditAccount { AccountNumber = "123456", Balance = 5000, CreditLimit = 3000 };
        try
        {
            atm.Withdraw(account, 12000);
        }
        catch (BadCashException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}